package cn.itsource.user.controller;

import cn.itsource.basic.util.PageList;
import cn.itsource.pet.domain.Pet;
import cn.itsource.pet.domain.PetDetail;
import cn.itsource.pet.query.PetQuery;
import cn.itsource.pet.service.IPetDetailService;
import cn.itsource.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 前台用户操作的controller ， 这些接口都需要放行
 *  /front/**
 */
@RestController
@RequestMapping("/front")
public class FrontController {

    @Autowired
    public IPetService petService;
    @Autowired
    public IPetDetailService petDetailService;

    /**
     * 分页查询宠物数据
     *  前台页面只能展示已上架的宠物
     * @param query 查询对象
     * @return PageList 分页对象
     */
    @PostMapping("/petList")
    public PageList<Pet> queryPagePetsList(@RequestBody PetQuery query) {
        query.setState(1);
        return petService.queryPage(query);
    }


    /**
     * 通过宠物id作为外键去查询宠物详情
     * @param petId
     * @return
     */
    @GetMapping("/findPetDetailByPetId/{petId}")
    public PetDetail findPetDetailByPetId(@PathVariable("petId")Long petId){
        return petDetailService.findByPetId(petId);
    }

}
